package com.probox.modules.controller.platfom;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.platfom.PlatformCmsClass;
import com.probox.common.entity.service.platfom.IPlatformCmsClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 信息分类Controller
 *
 *
 * @date 2021-06-11
 */
@RestController
@RequestMapping("/platform/cmsClass")
public class PlatformCmsClassController extends BaseController {
    @Autowired
    private IPlatformCmsClassService platformCmsClassService;

    /**
     * 查询信息分类列表
     */
    @PreAuthorize(hasPermi = "platform:cmsClass:list")
    @GetMapping("/list")
    public AjaxResult list(PlatformCmsClass platformCmsClass) {
        List<PlatformCmsClass> list = platformCmsClassService.queryList(platformCmsClass);
        return AjaxResult.success(list);
    }

    /**
     * 导出信息分类列表
     */
    @PreAuthorize(hasPermi = "platform:cmsClass:export")
    @Log(title = "信息分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlatformCmsClass platformCmsClass) throws IOException {
        List<PlatformCmsClass> list = platformCmsClassService.queryList(platformCmsClass);
        ExcelUtil<PlatformCmsClass> util = new ExcelUtil<PlatformCmsClass>(PlatformCmsClass.class);
        util.exportExcel(response, list, "信息分类数据");
    }

    /**
     * 获取信息分类详细信息
     */
    @PreAuthorize(hasPermi = "platform:cmsClass:query")
    @GetMapping(value = "/{cmsClassUid}")
    public AjaxResult getInfo(@PathVariable("cmsClassUid") String cmsClassUid) {
        return AjaxResult.success(platformCmsClassService.selectPlatformCmsClassById(cmsClassUid));
    }

    /**
     * 新增信息分类
     */
    @PreAuthorize(hasPermi = "platform:cmsClass:add")
    @Log(title = "信息分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlatformCmsClass platformCmsClass) {
        return toAjax(platformCmsClassService.insertPlatformCmsClass(platformCmsClass));
    }

    /**
     * 修改信息分类
     */
    @PreAuthorize(hasPermi = "platform:cmsClass:edit")
    @Log(title = "信息分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformCmsClass platformCmsClass) {
        return toAjax(platformCmsClassService.updatePlatformCmsClass(platformCmsClass));
    }

    /**
     * 删除信息分类
     */
    @PreAuthorize(hasPermi = "platform:cmsClass:remove")
    @Log(title = "信息分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cmsClassUids}")
    public AjaxResult remove(@PathVariable String[] cmsClassUids) {
        return toAjax(platformCmsClassService.deletePlatformCmsClassByIds(cmsClassUids));
    }
}
